package org.hawk.gwtppc.webtest.tests.classsuite;

import java.lang.reflect.Modifier;

import org.hawk.gwtppc.webtest.common.Asserts;
import org.hawk.gwtppc.webtest.common.Test;
import org.hawk.gwtppc.webtest.tests.mock.AnnotationMock;
import org.hawk.gwtppc.webtest.tests.mock.ClassMock;
import org.hawk.gwtppc.webtest.tests.mock.EnumMock;
import org.hawk.gwtppc.webtest.tests.mock.InterfaceMock;
import org.hawk.gwtppc.webtest.tests.mock.SubClassMock1;
import org.hawk.gwtppc.webtest.tests.mock.SubClassMock2;
import org.hawk.gwtppc.webtest.tests.mock.SubClassMock3;

public class GetConstructorTest implements Test {

	public void run() throws Throwable {
		try {
			AnnotationMock.class.getConstructor();
			Asserts.fail("Annotation has no constructors");
		} catch (NoSuchMethodException ex) {
		}
		try {
			InterfaceMock.class.getConstructor();
			Asserts.fail("Interface has no constructors");
		} catch (NoSuchMethodException ex) {
		}
		try {
			EnumMock.class.getConstructor();
			Asserts.fail("EnumMock has no public constructors");
		} catch (NoSuchMethodException ex) {
		}
		Asserts.assertEquals(ClassMock.class.getConstructor().toString(), "public org.hawk.gwtppc.webtest.tests.mock.ClassMock()");
		Asserts.assertEquals(ClassMock.class.getConstructor().getModifiers(), Modifier.PUBLIC);
		Asserts.assertEquals(SubClassMock1.class.getConstructor().toString(), "public org.hawk.gwtppc.webtest.tests.mock.SubClassMock1()");
		Asserts.assertEquals(SubClassMock1.class.getConstructor().getModifiers(), Modifier.PUBLIC);
		Asserts.assertEquals(SubClassMock2.class.getConstructor(String.class).toString(), "public org.hawk.gwtppc.webtest.tests.mock.SubClassMock2(java.lang.String)");
		Asserts.assertEquals(SubClassMock2.class.getConstructor(String.class).getModifiers(), Modifier.PUBLIC);
		Asserts.assertEquals(SubClassMock2.class.getConstructor(int.class).toString(), "public org.hawk.gwtppc.webtest.tests.mock.SubClassMock2(int)");
		Asserts.assertEquals(SubClassMock2.class.getConstructor(int.class).getModifiers(), Modifier.PUBLIC);
		try {
			SubClassMock2.class.getConstructor(boolean.class);
			Asserts.fail("SubClassMock2 has no public constructors");
		} catch (NoSuchMethodException ex) {
		}
		try {
			SubClassMock3.class.getConstructor();
			Asserts.fail("SubClassMock3 has no public constructors");
		} catch (NoSuchMethodException ex) {
		}
	}

	public String getName() {
		return "getConstructor(Class)";
	}

}
